package logic

import (
	"baidu/baidurpc/baidurpc"
	"context"

	"baidu/api/internal/svc"
	"baidu/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type PopularAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewPopularAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *PopularAddLogic {
	return &PopularAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *PopularAddLogic) PopularAdd(req *types.PopularRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	add, err := l.svcCtx.BaiDuRpc.PopularAdd(l.ctx, &baidurpc.PopularAddRequest{
		HeadImage: req.HeadImage,
		Context:   req.Context,
		Collect:   req.Collect,
		GiveNum:   req.GiveNum,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    nil,
			Code:    500,
		}, nil
	}

	return &types.Response{
		Message: "热门帖子添加成功",
		Data:    add,
		Code:    200,
	}, nil
}
